﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 玩具商城管理系统.start
{
    public partial class ChangePwd : Form
    {
        public ChangePwd()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnok_Click(object sender, EventArgs e)
        {
            if(txtPwd.Text=="")
            {
                MessageBox.Show("请输入密码");
            }
            else
            {
                DB.GetCn();
                string str = "select * from employee where employee_name='"+txtName.Text
                    +"'and employee_pwd='" + txtPwd.Text + "'";
                DataTable dt = DB.GetDataSet(str);
                if(dt.Rows.Count<1)
                {
                    MessageBox.Show("原密码错误请重新输入");
                }
                else
                {
                    if(txtNewpwd.Text=="" || txtNewpwd2.Text=="")
                    {
                        MessageBox.Show("请重新输入新密码");
                    }
                    else
                    {
                        if(txtNewpwd.Text!=txtNewpwd2.Text)
                        {
                            MessageBox.Show("两次新密码不一致，请重新输入");
                        }
                        else
                        {
                            string sdr="update employee set employee_pwd=' "
                                +txtNewpwd2.Text+"'where employee_name='"+txtName.Text+ "'";
                            DB.sqlEx(sdr);
                            MessageBox.Show("修改成功");
                            this.Close();
                        }
                    }
                }
            }
        }

        private void ChangePwd_Load(object sender, EventArgs e)
        {
            txtName.Text = login.username; 

        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
